home *** CD-ROM | disk | FTP | other *** search
/ Libris Britannia 4 / science library(b).zip / science library(b) / DJGPP / CBGRX103.ZIP / contrib / libgrx / fntool / readfna.c < prev    next >
Text File  |  1993-12-06  |  3KB  |  104 lines

  1. #include "fntool.h"
  2.  
  3. static void badfna(void)
  4. {
  5.     fatalerr("invalid \".fna\" file: \"%s\"",inname);
  6. }
  7.  
  8. static void readbitmap(chr *cp,char *rowp)
  9. {
  10.     int  xx,yy;
  11.  
  12.     for(xx = 0; (rowp[xx] == '#') || (rowp[xx] == '.'); xx++);
  13.     cp->width = xx;
  14.     cp->bmp = makebytemap(cp->width,fnt.height);
  15.     for(yy = 0; yy < fnt.height; yy++) {
  16.         if(yy != 0) rowp = readline();
  17.         for(xx = 0; xx < cp->width; xx++) {
  18.         switch(*rowp++) {
  19.             case '#': cp->bmp[yy][xx] = 1; break;
  20.             case '.': cp->bmp[yy][xx] = 0; break;
  21.             default:  badfna();
  22.         }
  23.         }
  24.     }
  25. }
  26.  
  27. void readfna(void)
  28. {
  29.     char *p;
  30.     char param[100],value[100];
  31.     chr  *cp,*last;
  32.     int  code;
  33.  
  34.     code = 0;
  35.     last = NULL;
  36.     fnt.isfixed = 1;
  37.     for( ; ; ) {
  38.         p = readline();
  39.         switch(p[0]) {
  40.           case ' ':
  41.           case ';':
  42.           case '\r':
  43.           case '\n':
  44.           case '\t':
  45.         continue;
  46.           case '.':
  47.           case '#':
  48.         cp = safemalloc(sizeof(chr));
  49.         readbitmap(cp,p);
  50.         cp->next = NULL;
  51.         *(last ? &last->next : &fnt.chars) = cp;
  52.         last = cp;
  53.         if(code < fnt.minchar) code = fnt.minchar;
  54.         cp->code = code;
  55.         if(++code > fnt.maxchar) break;
  56.         continue;
  57.           default:
  58.         param[0] = '\0';
  59.         if(sscanf(p,"%s %s",param,value) < 2)
  60.             { if(!strmatch(param,"note")) badfna(); }
  61.         else if(strmatch(param,"name"))
  62.             strcpy(fnt.name,value);
  63.         else if(strmatch(param,"family"))
  64.             strcpy(fnt.family,value);
  65.         else if(strmatch(param,"width"))
  66.             fnt.minwidth = fnt.maxwidth = fnt.avgwidth = atoi(value);
  67.         else if(strmatch(param,"height"))
  68.             fnt.height = atoi(value);
  69.         else if(strmatch(param,"minchar"))
  70.             fnt.minchar = atoi(value);
  71.         else if(strmatch(param,"maxchar"))
  72.             fnt.maxchar = atoi(value);
  73.         else if(strmatch(param,"minwidth"))
  74.             fnt.minwidth = atoi(value);
  75.         else if(strmatch(param,"maxwidth"))
  76.             fnt.maxwidth = atoi(value);
  77.         else if(strmatch(param,"avgwidth"))
  78.             fnt.avgwidth = atoi(value);
  79.         else if(strmatch(param,"isfixed"))
  80.             fnt.isfixed = atoi(value);
  81.         else if(strmatch(param,"undwidth"))
  82.             fnt.undwidth = atoi(value);
  83.         else if(strmatch(param,"baseline"))
  84.             fnt.baseline = atoi(value);
  85.         else if(strmatch(param,"note"))
  86.             strcat(notes,&p[5]);
  87.         else badfna();
  88.         continue;
  89.         }
  90.         break;
  91.     }
  92.     splitfamily();
  93.     if(fnt.undwidth == 0) fnt.undwidth = (fnt.height / 20) + 1;
  94.     if(fnt.baseline == 0) {
  95.         fnt.baseline = fnt.height - 1;
  96.         if((cp = getchr('a')) != NULL) {
  97.         while((fnt.baseline > 0) && !rowbit(cp->bmp,fnt.baseline)) {
  98.             fnt.baseline--;
  99.         }
  100.         }
  101.     }
  102. }
  103.  
  104.